/*
 * 
 * v1.2 by tonydon
 */
package cn.txdnet.txweb.mail;

import cn.txdnet.txweb.utils.VelocityUtil;
import java.util.Map;
import txdnet.util.StaticMark;
import txdnet.util.mail.SmtpMailer;

/**
 *
 * @author txdnet
 */
public class TemplateSender extends Sender {

    public TemplateSender() {
    }
    private String tomail;
    private String senderName;
    private String subject;
    private String mvtpl;
    private Map datamap;

    public TemplateSender(String tomail, String senderName, String subject, String mvtpl, Map datamap) {
        this.tomail = tomail;
        this.senderName = senderName;
        this.subject = subject;
        this.mvtpl = mvtpl;
        this.datamap = datamap;
    }

    @Override
    public Result dispatchMessages() {
        boolean flag = SmtpMailer.sendHtmlMail(
                getTomail(),
                getSenderName(),
                getSubject(),
                VelocityUtil.mergeTemplateToString(getMvtpl(), getDatamap(), StaticMark.ENCODING_UTF8),
                EmailConfig.getRandomSmtpParam());
        Result r = new Result();
        r.setSendFlag(flag);
        r.setMail(tomail);
        return r;
    }

    /**
     * @return the tomail
     */
    public String getTomail() {
        return tomail;
    }

    /**
     * @param tomail the tomail to set
     */
    public void setTomail(String tomail) {
        this.tomail = tomail;
    }

    /**
     * @return the senderName
     */
    public String getSenderName() {
        return senderName;
    }

    /**
     * @param senderName the senderName to set
     */
    public void setSenderName(String senderName) {
        this.senderName = senderName;
    }

    /**
     * @return the subject
     */
    public String getSubject() {
        return subject;
    }

    /**
     * @param subject the subject to set
     */
    public void setSubject(String subject) {
        this.subject = subject;
    }

    /**
     * @return the mvtpl
     */
    public String getMvtpl() {
        return mvtpl;
    }

    /**
     * @param mvtpl the mvtpl to set
     */
    public void setMvtpl(String mvtpl) {
        this.mvtpl = mvtpl;
    }

    /**
     * @return the datamap
     */
    public Map getDatamap() {
        return datamap;
    }

    /**
     * @param datamap the datamap to set
     */
    public void setDatamap(Map datamap) {
        this.datamap = datamap;
    }
}
